package controler;

import java.util.ResourceBundle;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;



public class AccountCodeValidator implements Validator {
	public static final String KEY_BAD_VALID = "message.validation.impossible";
	private static Pattern p = Pattern.compile("[0-9][0-9]-[0-9][0-9][0-9]", 
			   Pattern.MULTILINE);
	public void validate(FacesContext contexte, UIComponent composant,
			Object objet) throws ValidatorException {
		if (!(composant instanceof UIInput)) 
			return;
		if (!p.matcher(objet.toString()).matches()) {
			throw new ValidatorException(new FacesMessage(ResourceBundle.getBundle("i18n.Messages", contexte.getViewRoot().getLocale()).getString(KEY_BAD_VALID)));
		}
	}
}


